package com.heima.ThreadPool.ExecutorService3ways;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: Ethan Yankang
 * @Program: 面试必会代码
 * @Date: 2024-08-29 11:20
 **/
/*
 * @description 使用工厂方法来实现线程池的创建，注意这里本来就没有传入参数表名线程池中线程数量为多少的限制。
 * @params
 * @return
 */

public class newCachedThreadPool {
    public static void main(String[] args) {

        ExecutorService es = Executors.newCachedThreadPool(Executors.defaultThreadFactory());
        for (int i = 0; i < 10; i++) {
            final int taskId=i;
            es.submit(()->{
                System.out.println("线程"+Thread.currentThread().threadId()+"is running,taskId is"+taskId);
            });
        }
    }
}

/*
*原理仍然是7参数祖师爷来的
   public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) {
        return new ThreadPoolExecutor(0, Integer.MAX_VALUE,
                                      60L, TimeUnit.SECONDS,
                                      new SynchronousQueue<Runnable>(),
                                      threadFactory);
    }

*/
